using UnityEngine;

public class FollowTarget : MonoBehaviour
{
    public Transform targetTrans;
    private float lerpTime = 0.5f;
    Vector3 velocity = Vector3.zero;
    Vector3 viewPort = new Vector3(0.4f, 0.4f, 0);
    private void Update()
    {
        if (targetTrans != null)
        {
            Vector3 pos = Camera.main.WorldToViewportPoint(targetTrans.position);
            viewPort.z = pos.z;
            Vector3 offset = targetTrans.position - Camera.main.ViewportToWorldPoint(viewPort);
            Vector3 destination = transform.position + offset;


            transform.position = Vector3.SmoothDamp(transform.position, destination, ref velocity, lerpTime);


            //Vector3 cameraPos = transform.position;

            //if (destination.y > transform.position.y)
            //{
            //    cameraPos.y = Mathf.Lerp(transform.position.y, destination.y, lerpTime);
            //}
            //transform.position = cameraPos;
        }
    }
}

